<template>
  <div>
    <div id="header">
      <div class="img">
        <img src="../../assets/logo/logoName.png" alt="">
      </div>
    </div>
    <div class="scroll_box" ref="scroll_box">
    <div class="content">
      <div class="menu">
        <div :class="{activ:res.key==activ_key}" v-for="res in menu" :key="res.key" @click="goArticle(res)">{{res.title}}</div>
      </div>
      <div class="Agreement" id="Agreement" ref="Agreement">
        <div id="cookie" class="Agreement_c" ref="cookie">
          <div class="title">Cookie政策</div>
          <div class="article">
              <div v-html="cookie_html"></div>
          </div>
        </div>
        <div id="privacy" class="Agreement_c" ref="privacy">
          <div class="title">隐私政策</div>
          <div class="article">
              <div v-html="privacy_html"></div>
          </div>
        </div>
        <div id="softwareLicense" class="Agreement_c" ref="softwareLicense">
          <div class="title">软件许可及服务协议</div>
          <div class="article">
              <div v-html="softwareLicense_html"></div>
          </div>
        </div>
        <div id="accountUse" class="Agreement_c" ref="accountUse">
          <div class="title">个人账号使用规范</div>
          <div class="article">
              <div v-html="accountUse_html"></div>
          </div>
        </div>
        <div id="underAge" class="Agreement_c" ref="underAge">
          <div class="title">儿童隐私保护声明</div>
          <div class="article">
              <div v-html="underAge_html"></div>
          </div>
        </div>
        <div id="InformationProtectionConsulting" class="Agreement_c" ref="InformationProtectionConsulting">
          <div class="title">个人信息保护咨询指引</div>
          <div class="article">
              <div v-html="InformationProtectionConsulting_html"></div>
          </div>
        </div>
        <div id="privacyProtection_guidelines" class="Agreement_c" ref="privacyProtection_guidelines">
          <div class="title">隐私保证指引</div>
          <div class="article">
              <div v-html="privacyProtection_guidelines_html"></div>
          </div>
        </div>
        <div id="privacyProtection_abstract" class="Agreement_c" ref="privacyProtection_abstract">
          <div class="title">隐私保证指引摘要</div>
          <div class="article">
              <div v-html="privacyProtection_abstract_html"></div>
          </div>
        </div>
        <div id="operatingInstructions" class="Agreement_c" ref="operatingInstructions">
          <div class="title">操作说明及版本更新</div>
          <div class="article">
              <div v-html="operatingInstructions_html"></div>
          </div>
        </div>
        <div id="service" class="Agreement_c" ref="service">
          <div class="title">服务协议</div>
          <div class="article">
              <div v-html="service_html"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
import cookie from "./resources/cookie"
import privacy from "./resources/privacy"
import accountUse from "./resources/accountUse"
import operatingInstructions from "./resources/operatingInstructions"
import privacyProtection_abstract from "./resources/privacyProtection_abstract"
import privacyProtection_guidelines from "./resources/privacyProtection_guidelines"
import InformationProtectionConsulting from "./resources/InformationProtectionConsulting"
import service from "./resources/service"
import softwareLicense from "./resources/softwareLicense"
import underAge from "./resources/underAge"
export default {
  data() {
    return {
      cookie_html:'',
      privacy_html:'',
      softwareLicense_html:'',
      accountUse_html:'',
      underAge_html:'',
      InformationProtectionConsulting_html:'',
      privacyProtection_guidelines_html:'',
      privacyProtection_abstract_html:'',
      operatingInstructions_html:'',
      service_html:'',
      activ_key:'cookie',
      menu:[
        {
          title:'Cookie政策',
          key:'cookie'
        },
        {
          title:'隐私政策',
          key:'privacy'
        },
        {
          title:'软件许可及服务协议',
          key:'softwareLicense'
        },
        {
          title:'个人账号使用规范',
          key:'accountUse'
        },
        {
          title:'儿童隐私保护声明',
          key:'underAge'
        },
        {
          title:'个人信息保护咨询指引',
          key:'InformationProtectionConsulting'
        },
        {
          title:'隐私保证指引',
          key:'privacyProtection_guidelines'
        },
        {
          title:'隐私保证指引摘要',
          key:'privacyProtection_abstract'
        },
        {
          title:'操作说明及版本更新',
          key:'operatingInstructions'
        },
        {
          title:'服务协议',
          key:'service'
        }
      ]
    };
  },
  created(){
    this.cookie_html = cookie
    this.privacy_html = privacy
    this.softwareLicense_html = softwareLicense
    this.accountUse_html = accountUse
    this.underAge_html = underAge
    this.InformationProtectionConsulting_html = InformationProtectionConsulting
    this.privacyProtection_guidelines_html = privacyProtection_guidelines
    this.privacyProtection_abstract_html = privacyProtection_abstract
    this.operatingInstructions_html = operatingInstructions
    this.service_html = service
    window.addEventListener('scroll',this.handleScroll,true)
  },
  mounted(){
    this.menu.map(e=>{
      e.top = this.$refs[e.key].offsetTop
    })
    let key = this.$route.query.key || 'cookie'
    if(key!='cookie'){
      this.goArticle({key:key})
    }
  },
  destroyed(){
    window.removeEventListener('scroll', this.handleScroll,true);
  },
  methods: {
    getContainer(){
      return this.$refs.Agreement
    },
    getHtml(e){
      return this[e+'_html']
    },
    goArticle(e){
      // this.activ_key = e.key
      this.$refs[e.key].scrollIntoView({
        behavior: "smooth",  // 平滑过渡
        block:    "start"  // 上边框与视窗顶部平齐。默认值
      });
    },
    handleScroll(){
        let list = this.menu.filter(res=>res.top-60 <= this.$refs.scroll_box.scrollTop)
        if(list.length>0){
          this.activ_key = list[list.length-1].key
        }
    }
  },
};
</script>

<style scoped lang="less">
.scroll_box{
  height: calc(100vh - 40px);
  overflow: auto;
  background:#F8FBFF
}
#header{
  height: 40px;
  display: flex;
  background: #fff;
  .img{
    flex: 1;
    margin: 0 auto;
    max-width: 1000px;
    display: flex;
    align-items: center;
    img{
      width: 66px;
      height: 26px;
    }
  }
}
.content{
  display: flex;
  margin: 0 auto;
  padding-top: 20px;
  max-width: 1000px;
  .menu{
    width: 158px;
    background: #fff;
    max-height: calc(100vh - 80px);
    position: fixed;
    div{
      cursor: pointer;
      height: 39px;
      font-size: 11px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #6E7584;
      line-height: 39px;
      padding: 0 12px;
    }
    .activ{
      background: #F1F5FC;
      font-size: 11px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #206EF7;
      border-left: 3px solid #206EF7;
      box-sizing: border-box;
    }
  }
  .Agreement{
    width: calc(100% - 158px);
    margin-left: 158px;
    .Agreement_c{
      margin-left:16px;
      .title{
        font-size: 19px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #2878FF;
        line-height: 39px;
        padding-bottom: 30px;
      }
    }
    .Agreement_c:nth-last-of-type(1){
      min-height:100vh
    }
  }
}
</style>